//
//  BillListVC.m
//  jinwang
//
//  Created by jzb on 2018/3/12.
//  Copyright © 2018年 jzb. All rights reserved.
//

#import "BillListVC.h"
#import "BilleListCell.h"
#import "BillInfoVC.h"

@interface BillListVC ()

@property (nonatomic,strong) BilleListCell *cell;

@end

@implementation BillListVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"账单";
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self setUpTableView];
    BOOL isLogin = [[ToolManager sharedManager] checkLoginStateAtVC:self];
    if (isLogin) {
        
        [self net_getBillList_with_token];
    }
}
//配置tableView
-(void)setUpTableView{
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.edgesForExtendedLayout = UIRectEdgeNone;
    self.tableView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    //注册cell
    self.isGroupTable = YES;
    [self registerCellWithCellClassArray:@[NSStringFromClass([BilleListCell class])]];
    
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        BOOL isLogin = [[ToolManager sharedManager] checkLoginStateAtVC:self];
        if (isLogin) {
            
            [self net_getBillList_with_token];
        }
    }];
}
#pragma mark -UITableViewDelegate,UITableViewDataSource
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 3;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 10;
}
//返回每组头部view
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    UIView *headerView = [[UIView alloc]init];
    
    headerView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    
    UILabel *label = [[UILabel alloc]init];
    
    label.textColor = [UIColor grayColor];
    
    label.font = [UIFont systemFontOfSize:16];
    
    label.frame = CGRectMake(10, 10, 100, 20);
    
    [headerView addSubview:label];
    
    if (section == 0) {
        
        label.text = @"第0组title";
        
    }else{
        
        label.text = @"第1组title";
        
    }
    
    return headerView;
    
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    self.cell = [tableView dequeueReusableCellWithIdentifier:[BilleListCell getCellReuseIdentifier]];
    self.cell.contentView.backgroundColor = [UIColor clearColor];
    
//    [self.cell.GeRenZiLiaoBtn addTarget:self action:@selector(cellButtonOnclikc:) forControlEvents:UIControlEventTouchUpInside];
//    [self.cell.MyWalletBtn addTarget:self action:@selector(cellButtonOnclikc:) forControlEvents:UIControlEventTouchUpInside];
//    [self.cell.MyCollectBtn addTarget:self action:@selector(cellButtonOnclikc:) forControlEvents:UIControlEventTouchUpInside];
//    [self.cell.BackCardBtn addTarget:self action:@selector(cellButtonOnclikc:) forControlEvents:UIControlEventTouchUpInside];
//    [self.cell.ConfigurationBtn addTarget:self action:@selector(cellButtonOnclikc:) forControlEvents:UIControlEventTouchUpInside];
    //    [self.cell.zhaocheBut addTarget:self action:@selector(cellButtonOnclikc:) forControlEvents:UIControlEventTouchUpInside];
    
    
    return self.cell;
}
// 返回组头部view的高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 40;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 80;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    BillInfoVC *VC = [BillInfoVC new];
    
    [self.navigationController pushViewController:VC animated:YES];
}
#pragma mark -网络请求
//获取用户信息
-(void)net_getBillList_with_token{
    [[DDNetworkManagerDate makeUrl_billList_with_token:k_user_token] post_RequestFinshSuccess:^(id responseObject) {
        [self.tableView.mj_header endRefreshing];
        
        NSLog(@"-=-=-=>>%@",responseObject);
        if ([self requestFinshCode:responseObject isShowMessage:YES] == 1) {
            
            NSDictionary *data = [responseObject objectForKey:kRequsetDataKey];
//            self.model_userInfo = [UserInfoModel yy_modelWithDictionary:data];
        }
        
        //刷新
        [self.tableView reloadData];
    } failure:^(id errorObject) {
        [self.tableView.mj_header endRefreshing];
        [self showBottomMessag:@"网络请求失败"];
    }];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
